package com.example.chinesenation.Response;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author sakuraFallingDown
 * @version 1.0
 * @date 2021/1/11 15:59
 */
@JsonSerialize
@Data
@AllArgsConstructor
@NoArgsConstructor
public  class ServerResponse<T> {
    @JsonInclude(JsonInclude.Include.NON_NULL)  //  为空时省略该属性
    private int resultCode;
    @JsonInclude(JsonInclude.Include.NON_NULL)  //  为空时省略该属性
    private String msg;
    @JsonInclude(JsonInclude.Include.NON_NULL)  //  为空时省略该属性
    private T data;
    public static<T> ServerResponse<T> createSuccessResponse(String msg){
        return new ServerResponse<T>(20000,msg,null);
    }
    public static <T> ServerResponse<T> createSuccessResponse(String msg,T data){
        return new ServerResponse<T>(20000,msg,data);
    }
    public static <T> ServerResponse<T> createErrorsResponse(ResultType resultType) {
        return new ServerResponse<T>(resultType.getCode(),resultType.getMsg(),null);
    }

}
